package com.pxx.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxx.item.mapper.TbStockMapper;
import com.pxx.item.pojo.TbSku;
import com.pxx.item.pojo.TbStock;
import com.pxx.item.service.TbSkuService;
import com.pxx.item.mapper.TbSkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
* @author Yoo19
* @description 针对表【tb_sku(sku表,该表表示具体的商品实体,如黑色的 64g的iphone 8)】的数据库操作Service实现
* @createDate 2025-06-27 19:16:16
*/
@Service
public class TbSkuServiceImpl extends ServiceImpl<TbSkuMapper, TbSku>
    implements TbSkuService{
    @Autowired
    private TbSkuMapper tbSkuMapper;
    @Autowired
    private TbStockMapper tbStockMapper;

    @Override
    public List<TbSku> querySkuListBySpuId(Long id) {
        QueryWrapper<TbSku> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("spu_id",id);
        //根据spuId查找Sku数据
        List<TbSku> skus = tbSkuMapper.selectList(queryWrapper);
        //根据sku的数据列表查询对应的库存量
        for (TbSku sku : skus) {
            TbStock tbStock = tbStockMapper.selectById(sku.getId());
            sku.setStock(tbStock.getStock());
        }
        return skus;
    }
}




